package com.relytosoft.mizar.media.host;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
import com.alicp.jetcache.anno.config.EnableMethodCache;
import com.relytosoft.mizar.media.common.emqx.client.EmqxClient;
import com.relytosoft.mizar.media.common.emqx.config.MqttConfiguration;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @author Jierry
 * @version 2022/4/20.
 */
@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class)
@EnableMethodCache(basePackages = "com.relytosoft")
@EnableCreateCacheAnnotation
@MapperScan("com.relytosoft.**.mapper")
@EnableFeignClients(basePackages = {"com.relytosoft.mizar.media.external.**.feign","com.relytosoft.**.api.feign"})
@EnableAsync(proxyTargetClass=true )
@EnableScheduling
public class MediaApplication {
    public static void main(String[] arge){
        SpringApplication.run(MediaApplication.class,arge);
    }

    @Resource
    private EmqxClient emqClient;

    @Resource
    private MqttConfiguration properties;

    /**
     * 开启订阅指定主题消息
     */
    @PostConstruct
    public void init() {
        emqClient.connect(properties.getHost(),properties.getClientid(),properties.getUsername(),properties.getPassword(),properties.getTimeout(),properties.getKeepalive(),properties.getTopic());

    }
}
